% According to externalize.tex from the example folder of Package todonotes.

\usepackage{xspace}
\usepackage{tikz}
\ifx\CompileTikZFigures\undefined
	\usetikzlibrary{external}
	\tikzexternalize[prefix=pics/tikz/]
\fi

\usepackage[colorinlistoftodos,textsize=footnotesize]{todonotes}

\ifx\CompileTikZFigures\undefined
	\makeatletter
	\renewcommand{\todo}[2][]{%
		\tikzexternaldisable%
		\@bsphack\@todo[#1]{#2}\@esphack\ignorespaces%
		\tikzexternalenable%
		\xspace%
		}
	\makeatother
\else
	\makeatletter
	\renewcommand{\todo}[2][]{%
		\@bsphack\@todo[#1]{#2}\@esphack\ignorespaces\xspace%
	}
	\makeatother
\fi
% According to https://tex.stackexchange.com/a/178806/104838 with
% some modifications.
\usepackage{xargs}  % Use more than one optional parameter in a new commands
\newcommandx{\tdnow}[2][1=]{\todo[linecolor=red,backgroundcolor=red!58,bordercolor=red,#1]{#2}}
% Example
% \tdnow[inline, caption=
%     \textbf{Todo now:} Design Algorithm 1.
% ]{
%     \begin{minipage}{\linewidth}
%         \textbf{Todo now:} Design Algorithm 1.
%         \emph{Prerequisite:}
%             \begin{itemize}
%                 \item Understand Theorem 1 and 2.
%             \end{itemize}
%     \end{minipage}
% }
\newcommandx{\tdnext}[2][1=]{\todo[linecolor=yellow,backgroundcolor=yellow!58,bordercolor=yellow,#1]{#2}}
\newcommandx{\tdst}[2][1=]{\todo[linecolor=blue,backgroundcolor=blue!58,bordercolor=blue,#1]{#2}}
\newcommandx{\info}[2][1=]{\todo[linecolor=OliveGreen,backgroundcolor=OliveGreen!25,bordercolor=OliveGreen,#1]{#2}}
\newcommandx{\improvement}[2][1=]{\todo[linecolor=Plum,backgroundcolor=Plum!25,bordercolor=Plum,#1]{#2}}
\newcommandx{\thiswillnotshow}[2][1=]{\todo[disable,#1]{#2}}

% According to the document of Package todonotes.
\usepackage{soul}
\makeatletter
\if@todonotes@disabled
\newcommand{\hlfix}[2]{#1}
\else
\newcommand{\hlfix}[2]{\texthl{#1}\todo{#2}}
\fi
\makeatother

% Revised version from todoin in the document of Package todonotes.
\newcommand\tdnowin[2][]{\todo[inline,linecolor=red,backgroundcolor=red!58,bordercolor=red, #1]{
\begin{minipage}{\textwidth-4pt}#2\end{minipage}}}
% Example:
% \tdnowin[caption=
%     \textbf{Todo now:} Design Algorithm 1.
% ]{
%     \begin{minipage}{\linewidth}
%     \textbf{Todo now:} Design Algorithm 1.
%     \emph{Prerequisite:}
%         \begin{itemize}
%             \item Understand Theorem 1 and 2 in this paper.
%         \end{itemize}
%     \end{minipage}
% }

